﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhDataAcess.baseBLL;
using System.Data.SqlClient;
using baseSet;
using dhSystemBLL.basicData;
using dhDataAcess.dataAcess;
namespace dhsystem.Main
{
    public partial class FrmLogin : Form
    {
        basListBLL basList = new basListBLL();
        public FrmLogin()
        {
            InitializeComponent();
        }
        
        public string sUserName
        {
            get { return this.textuser .Text ; }
        }
        private void buttLogin_Click(object sender, EventArgs e)
        {
            string userName = textuser.Text.ToString ().Trim ();
            string userPasswords = textpasswords.Text.ToString().Trim();

            basicSql.baslistBasNumUpdateOrderSerial("单位编号");
            basicSql.baslistBasNumUpdateOrderSerial("订单序列号");
            basicSql.baslistBasNumUpdateOrderSerial("领料单序列号");
            basicSql.baslistBasNumUpdateOrderSerial("胚带入库单号");
            basicSql.baslistBasNumUpdateOrderSerial("包装入库单号");
            basicSql.baslistBasNumUpdateOrderSerial("订单成品出库单号");
            basicSql.baslistBasNumUpdateOrderSerial("订单成品退库单号");
            basicSql.baslistBasNumUpdateOrderSerial("领料出库单号");
            basicSql.baslistBasNumUpdateOrderSerial("领料退库单号");
            basicSql.baslistBasNumUpdateOrderSerial("采购订单号");
            basicSql.baslistBasNumUpdateOrderSerial("采购收货入库单号");
            basicSql.baslistBasNumUpdateOrderSerial("采购退货单号");
            basicSql.baslistBasNumUpdateOrderSerial("生产单号");
            basicSql.baslistBasNumUpdateOrderSerial("漂染单号");
            basicSql.baslistBasNumUpdateOrderSerial("备料单号");
            basicSql.baslistBasNumUpdateOrderSerial("排期号");
            basicSql.baslistBasNumUpdateOrderSerial("胚带出库单号");
            basicSql.baslistBasNumUpdateOrderSerial("五金编号");
            GlobalInfo.Date  = getDate();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = dataConn.connOpen();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select userNum,pwd from userList where userNum='" + userName + " '";
            SqlDataReader dr= cmd.ExecuteReader();
            if (dr.Read())
            {
                if (dr["pwd"].ToString().Trim() == userPasswords)
                {
                    this.Visible = false;
                    GlobalInfo.UserName  = userName;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    
                }
            
            else
            {
                textpasswords .Text  = "";
                MessageBox.Show("密码错误，请重新输入！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            }
            }
          
            else 
            {
                 textuser.Text = ""; textpasswords.Text = "";
                 MessageBox.Show("此用户不存在，请您注册！", "注册", MessageBoxButtons.OK, MessageBoxIcon.Information); }
                dataConn .connOpen ().Close (); 
                 dr.Close();
           }

        private void buttexit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private string  getDate()
        {
            string NowYear = DateTime.Now.ToString("yyyy");
            string NowMouth = DateTime.Now.ToString("MM");
            string NowDay = DateTime.Now.ToString("dd");
            if (NowMouth.Length  == 1)
            {
                NowMouth = "0" + NowMouth;
            }
            if (NowDay.Length  == 1)
            {
                NowDay = "0" + NowDay;
            }
            string NowTime = NowYear + NowMouth + NowDay;
            return NowTime;
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {

        }

       
        
           }
        }
  
  
